<?php


namespace app\admin\controller;
use app\admin\model\Users as UserModel;
use think\Controller;

class Users extends Controller
{
    public function listpage(){
        $model=new UserModel();
        $udata = $model->getList();
        $this->assign('udata', $udata);
       return $this->fetch();
    }
    function add(){
        return $this->fetch();
    }

    function doadd(){
        $data=$this->request->param();
        $model=new UserModel();
        $res=$model->save($data);
        if($res){
            return alert_success('添加成功','users/listpage');
        }else{
            return alert_error('添加失败，请检测输入!');
        }

    }

    function edit($no){
        $model=new UserModel();
        $udata=$model->getUser($no);
        $this->assign('data', $udata);
       return $this->fetch();
    }
    function mod(){
        $data=$this->request->param();
        $model=new UserModel();
        $res=$model->updateUser($data);
        if ($res) {
            return alert_success('修改成功','users/listpage');
        } else {
            return alert_error('修改失败','users/edit');
        }
    }


    function del($no){
        $model=new UserModel();
        $res=$user=$model->deluser($no);
        if($res){
            return alert_success('删除数据成功!','users/listpage');
        }else{

            return alert_error('删除数据失败!');
        }
    }

}